<template>
    <div class="tabs-layout">
        <div class="rx-tabs-layout">
            <div :class="[tabItem.id==activeKey?'rx-tabs-layout-top-after':'rx-tabs-layout-top']" v-for="tabItem in tabList" @click="activeKey =tabItem.id"> {{tabItem.name}}</div>
        </div>
        <div v-for="(tabItem,index) in tabList">
            <template v-if="tabItem.id==activeKey && tabItem.defConf">
                <FormCustomControl :paramsCustom="paramsCustom" :item="tabItem" :style="getStyle(tabItem)"></FormCustomControl>
            </template>
        </div>
    </div>
</template>

<script>
/**
 * 自定义页面(tab容器组件)
 */
import {defineAsyncComponent } from 'vue'
import FormCustomPublic from "../FormCustomPublic";
export default {
    name: "tabContainerView",
    mixins:[FormCustomPublic],
    components: {
        FormCustomControl:defineAsyncComponent(()=>import('@/views/modules/form/FormCustomView/GridLayoutView/FormCustomControl.vue')),
    },
    props: {
        config: {}
    },
    data() {
        return {
            activeKey: "1",
            tabList: [],
            params:{},
        }
    },
    created() {
        this.params=this.getRouterParams();
        this.initConfig();
        if (this.tabList.length > 0) {
            this.activeKey = this.tabList[0].id;
        }
    },
    methods: {
        initConfig() {
            this.tabList = [];
            if (this.config && this.config.tabs) {
                this.tabList.push(...this.config.tabs);
            }
        },
        getStyle(item){
            let style = {}
            let list = ['chart']
            if(list.contains(item.defConf)){
                style['overflow'] = 'hidden'
                style['height'] = '300px'
            }
            return style
        }
    },
    watch: {
        config: {
            handler: function (val, oldval) {
                this.initConfig();
            },
            deep: true
        },
    },
}
</script>

<style scoped>
.tabs-layout{
    width: 100%;
    background: white;
    padding: 0.5rem;
    box-sizing: border-box;
    border-radius: 5px;
}
.rx-tabs-layout{
    display: flex;
    flex-direction: row;
    overflow: auto;
}
.rx-tabs-layout-top{
    height: 1.6rem;
    line-height: 1.5rem;
    margin: 0px 0.5rem;
    position: relative;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.rx-tabs-layout-top-after{
    height: 1.5rem;
    line-height: 1.5rem;
    margin: 0px 0.5rem;
    position: relative;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #0a84ff;
}
.rx-tabs-layout-top-after::after{
    content: '';
    position: absolute;
    left: calc(50% - 10px);
    top: 1.5rem;
    z-index: 1;
    width: 20px;
    height: 3px;
    background: #0a84ff;
}
.rx-tabs-layout-center{
    width: 100%;
    min-height: 50px;
    border: 1px solid #eee9e9;
    box-sizing: initial;
    border-radius: 5px;
    margin-top: 10px;
}
</style>
